/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.biz.repository;

import me.zhengjie.modules.biz.domain.Cabinet;
import me.zhengjie.modules.biz.domain.HazardousChemicals;
import me.zhengjie.modules.biz.service.dto.CabinetDto;
import org.checkerframework.checker.units.qual.C;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

/**
* @website https://eladmin.vip
* @author Admin
* @date 2023-03-13
**/
public interface CabinetRepository extends JpaRepository<Cabinet, Integer>, JpaSpecificationExecutor<Cabinet> {
    @Query(value = "select * from hj_cabinet",nativeQuery = true)
    List<Cabinet> findAllList();

    @Query(value = "SELECT * FROM hj_cabinet WHERE mac = ?1 limit 0,1",nativeQuery = true)
    Cabinet findByMac(String mac);

    @Query(value = "select distinct lab_id from hj_cabinet where type = 1 ",nativeQuery = true)
    List<Integer> cabinetList();

    List<Cabinet> findByLabId(Integer labId);

    @Query(value = "SELECT * FROM hj_cabinet WHERE type = ?1",nativeQuery = true)
    List<Cabinet> findByType(int type);

    @Query(value = "SELECT l.floor, count(*) count FROM hj_cabinet s, hj_lab l where l.id = s.lab_id and s.type = 2 group by floor order by floor",nativeQuery = true)
    List<Map<String, Object>> getCountByFloor();

    @Query(value = "SELECT s.name, s.temperature, s.humidity, s.position FROM hj_cabinet s, hj_lab l where l.id = s.lab_id and s.type = 2 and l.floor = ?1",nativeQuery = true)
    List<Map<String, Object>> getRefrigeratorListByFloor(Integer floor);
}
